package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.ChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {
    @Autowired
    private WmChannelService wmChannelService;

    /**
     * 自媒体频道列表查询
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult channels(){
        return wmChannelService.findAllChannel();
    }

    /**
     * 后台管理平台频道查询
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ChannelDto channelDto){
        return wmChannelService.findChannel(channelDto);
    }

    /**
     * 后台保存自媒体品频道
     * @param wmChannel
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmChannel wmChannel){
        return wmChannelService.saveChannel(wmChannel);
    }

    /**
     * 后台修改频道信息
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmChannel wmChannel){
        return wmChannelService.updateChannel(wmChannel);
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id){
        return wmChannelService.deleteChannel(id);
    }
}
